<template> 
  <el-dialog :visible.sync="visible" width="80%" hight="75%" :before-close="close">
    <div class="app-container">
      <el-card class="filter-container" shadow="never">
        <div>
          <i class="el-icon-search"></i>
          <span>筛选搜索</span>
          <el-button style="float:right" type="primary" @click="handleSearchList()" size="s米糕">
            查询搜索
          </el-button>
          <el-button style="float:right;margin-right: 15px" @click="handleResetSearch()" size="s米糕">
            重置
          </el-button>
        </div>
        <div style="margin-top: 15px">
          <el-form :inline="true" :model="listQuery" size="s米糕" label-width="140px">
            <el-form-item label="输入搜索：">
              <el-input v-model="listQuery.username" class="input-width" placeholder="帐号" clearable>
              </el-input>
            </el-form-item>
            <el-form-item label="手机号：">
              <el-input v-model="listQuery.mobilePhone" class="input-width" placeholder="手机号" clearable>
              </el-input>
            </el-form-item>
          </el-form>
        </div>
      </el-card>
      <el-card class="operate-container" shadow="never">
        <i class="el-icon-tickets"></i>
        <span>数据列表</span>
        <el-button size="mini" class="btn-add" @click="handleAdd()" style="margin-left: 20px">确定</el-button>
      </el-card>
      <div class="table-container">
        <el-table 
          ref="adminTable" 
          :data="list"
          @select="" 
          style="width: 100%;" 
          v-loading="listLoading" 
          border>
          <el-table-column label="编号" width="100" align="center">
            <template slot-scope="scope">
              <input
               type="radio" 
                name="id" :value="scope.$index"
                @click="radioSelect" />
            </template>
          </el-table-column>
          <el-table-column label="编号" width="100" align="center">
            <template slot-scope="scope">{{ scope.row.id }}</template>
          </el-table-column>
          <el-table-column label="头像" width="200" align="center">
            <template slot-scope="scope"><img width="100" height="100" :src="ossURL + scope.row.avatar" /></template>
          </el-table-column>
          <el-table-column label="帐号" align="center">
            <template slot-scope="scope">{{ scope.row.username }}</template>
          </el-table-column>
          <el-table-column label="昵称" align="center">
            <template slot-scope="scope">{{ scope.row.nickname }}</template>
          </el-table-column>
          <el-table-column label="邮箱" align="center">
            <template slot-scope="scope">{{ scope.row.email }}</template>
          </el-table-column>
          <el-table-column label="生日" width="160" align="center">
            <template slot-scope="scope">{{ scope.row.birthday | formatDateTime }}</template>
          </el-table-column>
          <el-table-column label="添加日期" width="160" align="center">
            <template slot-scope="scope">{{ scope.row.createTime | formatDateTime }}</template>
          </el-table-column>
          <el-table-column label="手机号" width="140" align="center">
            <template slot-scope="scope">{{ scope.row.mobilePhone }}</template>
          </el-table-column>
          <el-table-column label="铸造的nft数量" align="center">
            <template slot-scope="scope">{{ scope.row.buildNftNumber }}</template>
          </el-table-column>
          <el-table-column label="拥有的nft数量" align="center">
            <template slot-scope="scope">{{ scope.row.transactionNumber }}</template>
          </el-table-column>
          <el-table-column label="性别" align="center">
            <template slot-scope="scope">{{ sex[scope.row.gender] }}</template>
          </el-table-column>
        </el-table>
      </div>
      <div class="pagination-container">
        <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
          layout="total, sizes,prev, pager, next,jumper" :current-page.sync="listQuery.pageNum"
          :page-size="listQuery.pageSize" :page-sizes="[15]" :total="total">
        </el-pagination>
      </div>
    </div>
  </el-dialog>
</template>
<script>
import { UserController } from '../../components/SelectUser/index';
import { formatDate } from '@/utils/date';

import { getUserListBySearch } from "../../api/user"
const user = new UserController();

export default {
  props: {
    visible: {
      type: Boolean,
      default: false
    }
  },

  data() {
    return user.getCurrentData()
  },

  watch: {
    'listQuery.username': (val) => {
      console.log("val", val);
    }
  },
  filters: {
    formatDateTime(time) {
      if (time == null || time === '') {
        return 'N/A';
      }
      let date = new Date(time);
      return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
    }
  },

  methods: {
    ...user.methods,

    select(selection, row) {
      console.log("selection", selection, "row", row);
    },

    radioSelect(element) {
      console.log("element", element);
      this.radioCheckIndex = element.target.value;
    },
    handleAdd() {
      console.log("this.radioCheckIndex",this.radioCheckIndex, this.list);
      this.$emit("recevice", this.list[this.radioCheckIndex]);
      this.close();
    },

    getUserList() {
      user.created(this)
    },
    close() {
      this.$emit("updateEdit", false);
    },
    handleSearchList(val) {
      getUserListBySearch(this.listQuery, this)
    },

  }
}

</script>


